package com.jamaskii.thread;

public class Task {
    public final static int STATUE_COMPLETE=-1;
    public final static int STATUE_LIVE=-2;
    public final static int STATUE_EXCEPTION=-3;
    public final static int STATUE_RAW=-4;

    public Object tag;
    public int statue=STATUE_RAW;
    private Runnable todo;
    public Runnable onDone;
    public Runnable onException;
    public boolean done=false;

    public Task(Runnable run){
        this.todo=run;
    }

    public void start(){
        try{
            statue=STATUE_LIVE;
            todo.run();
            statue=STATUE_COMPLETE;
            done=true;
            if(onDone!=null){
                onDone.run();
            }
        }catch (Exception e){
            statue=STATUE_EXCEPTION;
            done=true;
            if(onException!=null){
                onException.run();
            }
        }
    }
}
